package com.hnevc.wangyu;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.hnevc.wangyu.activity.LoginActivity;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private TextView time;
    private Timer timer;
    int date = 6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();


    }

    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        time = (TextView) findViewById(R.id.time);
        time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, LoginActivity.class));
                timer.cancel();
                finish();
            }
        });
        setView();

    }

    private void setView() {

        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        time.setText("倒计时( "+ date +" )点击跳过");
                    }
                });

                if (date < 1){
                    startActivity(new Intent(MainActivity.this, LoginActivity.class));
                    timer.cancel();
                    finish();
                }
                date--;

            }
        },500,1000);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer.cancel();
    }
}